<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除图书</title>
    <!--  第一种删除方法，不过这里比较笨拙，没有体现到ajax的便捷  -->
    <script src="./js/jquery-2.1.0.js"></script>
    <style>
        body {
            background: url("./img/bj4.png") no-repeat;
            font-family: Arial, sans-serif;
            background-color: #f0f0f0;
            text-align: center;
            margin: 0;
            padding: 20px;
        }

        table {
            width: 80%;
            margin: 20px auto;
            border-collapse: collapse;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        table, th, td {
            border: 1px solid #ccc;
        }

        th, td {
            padding: 10px;
            text-align: center;
        }

        th {
            background-color: #4CAF50;
            color: white;
        }

        tr {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>图书添加</h2>
<table id="Booktable">
    <thead>
    <tr>
        <th>书名</th>
    </tr>
    </thead>
    <tbody id="bookName">
    <tr>
        <td><input type="text" id="bname" name="bname" placeholder="书名"></td>
    </tr>
    </tbody>
</table>
<button type="submit" onclick="del()">删除</button>
<button type="button" onclick="btn()">返回</button>

<script>

    function del() {
        var msg = "您确定要删除吗？";
        if (confirm(msg) == true) {
            $.ajax({
                type: "GET",
                url: "/delBook",
                data: {
                    "bname": $("#bname").val(),
                },
                dataType: "JSON",
                success: function (bookresult) {
                    console.log(bookresult)
                    if (bookresult.code == 20000) {
                        alert(bookresult.msg);
                        var json = JSON.stringify(bookresult.data);
                        sessionStorage.setItem("BookList", json)
                        location.assign("BookList.html");
                    } else {
                        alert(bookresult.msg);
                    }
                }
            });
            return true;
        } else {
            return false;
        }

    }

    <!-- 跳转首页 -->
    function btn() {
        location.assign("menu.html");
    }
</script>
</body>
</html>